/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc.dao;

/**
 *
 * @author pezcado
 */

import java.io.*;
import java.sql.*;
import mvc.modelos.Rol;

public class Model implements Serializable{

    private static Connection con;
    private static Model model;

    static Model getInstance() throws SQLException {
        if(model==null)
            model=new Model();
        model.conectar();
        return model;
        
    }
    
    private String jdbcDriver;
    private String jdbcUrl;
    private String user;
    private String password;
    private String database;
    private String puerto;
    
   public Model(){
       jdbcDriver="com.mysql.jdbc.Driver";
       user="root";
       password="1234";
       database="ModeloProyectoBienestarUniversitario";
       puerto="";
       jdbcUrl="jdbc:mysql://localhost:3306/";
   }
    
    /**
     * @return the con
     */
    public static Connection getCon() throws SQLException {
        return con;
    }
    
    public String getJdbcDriver() {
        return jdbcDriver;
    }

    public void setJdbcDriver(String jdbcDriver) {
        this.jdbcDriver = jdbcDriver;
    }

    public String getJdbcUrl() {
        return jdbcUrl;
    }

    public void setJdbcUrl(String jdbcUrl) {
        this.jdbcUrl = jdbcUrl;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

        /**
     * @return the puerto
     */
    
    public String getPuerto() {
        return puerto;
    }

    /**
     * @param puerto the puerto to set
     */
    
    public void setPuerto(String puerto) {
        this.puerto = puerto;
    }

    public void conectar() throws SQLException {
        try {
            Class.forName(this.jdbcDriver);
        } catch (ClassNotFoundException ex) {
            throw new SQLException("Driver no cargado !!!"+ex.toString());
        }
        System.out.println("------------Conexion Driver--------- :"+this.getJdbcUrl()+this.getDatabase()+","+this.getUser()+","+this.getPassword());
        con = DriverManager.getConnection(this.getJdbcUrl()+this.getPuerto()+this.getDatabase(), this.getUser(), this.getPassword());
    }
    
    public boolean isConnect() throws SQLException{
        if(getCon()!=null)
        {
           return true;
        }else
        {
           return false;
        }
    }
    
    public void disconnect() throws SQLException{
        if(getCon()!=null)
        {
            try
            {
                getCon().close();
            }catch(SQLException ignore){}
            finally
            {
              con=null;
            }
        }
    }
    
    public PersonaDAO getPersonaDAO(){
        return new PersonaDAO();
    }
    
    public RolDAO getRolDAO(){
        return new RolDAO();
    }
    
    public CuentaDAO getCuentaDAO(){
        return new CuentaDAO();
    }
    
    public IntegranteDAO getIntegranteDAO(){
        return new IntegranteDAO();
    }
    
    public JefeDeCulturaDAO getJefeDeCulturaDAO(){
        return new JefeDeCulturaDAO();
    }
    
    public SecretariaDAO getSecretariaDAO(){
        return new SecretariaDAO();
    }
    
    public DirectorDeGrupoDAO getDirectorDeGrupoDAO(){
        return new DirectorDeGrupoDAO();
    }
    
    public AspiranteDAO getAspiranteDAO(){
        return new AspiranteDAO();
    }
        
    public ActividadCulturalDAO getActividadCulturalDAO(){
        return new ActividadCulturalDAO();
    }
    
    public ConvocatoriaDAO getConvocatoriaDAO(){
        return new ConvocatoriaDAO();
    }
    
    public ConvocatoriaHasSemilleroTallerGrupoRepresentativoDAO getConvocatoriaHasSemilleroTallerGrupoRepresentativoDAO(){
        return new ConvocatoriaHasSemilleroTallerGrupoRepresentativoDAO();
    }
    
    public GrupoFamiliarDAO getGrupoFamiliarDAO(){
        return new GrupoFamiliarDAO();
    }
    
    public HistoriaClinicaDAO getHistoriaClinicaDAO(){
        return new HistoriaClinicaDAO();
    }
    
    public HojaDeVidaDAO getHojaDeVidaDAO(){
        return new HojaDeVidaDAO();
    }
    
    public HorarioDAO getHorarioDAO(){
        return new HorarioDAO();
    }
    
    public InscripcionDAO getInscripcionDAO(){
        return new InscripcionDAO();
    }
    
    public SemilleroTallerGrupoRepresentativoDAO getSemilleroTallerGrupoRepresentativoDAO(){
        return new SemilleroTallerGrupoRepresentativoDAO();
    }
    
    public SeguimientoDAO getSeguimientoDAO(){
        return new SeguimientoDAO();
    }
}
